layui.use(['layer', 'miniTab', 'echarts'], function () {
    var $ = layui.jquery,
        layer = layui.layer,
        miniTab = layui.miniTab;
    miniTab.listen();
});
// 页面数据请求
$.get({
    url:'/homepage/getTodayPriceAndCount',
    data:{},
    dataType:'json',
    sync:false,
    success:res=>{
        if(res.state == '200'){
            $('.price').text('￥'+res.data.price)
            $('.count').text(res.data.todayCount)
        }else{
            $('.price').text('0')
            $('.count').text('0')
        }
    }
})
$.get({
    url:'/homepage/getJoinAndPre',
    data:{},
    dataType:'json',
    sync:false,
    success:res=>{
        if(res.state == '200' && res.data != null){
            $('.joinSchool').text('￥'+res.data.joinSchool)
            $('.pre').text(res.data.pre)
        }else{
            $('.joinSchool').text('0')
            $('.pre').text('0')
        }
    }
})
//绑定echarts模板
var generates = echarts.init(document.getElementById('generates'))
var payment = echarts.init(document.getElementById("payment"))
// 指定图表的配置项和数据
$.get({
    url:'/homepage/getOneMouthPrice',
    data:{},
    dataType:'json',
    success:res=>{
        var dayDate = []
        var dayPrice = []
        $.each(res.data,function (i){
            dayDate[i] = res.data[i].day
            dayPrice[i] = res.data[i].dayPrice/1000
        })
        var optiongenerates = {
            title: {
                text: '最近一个月每日订单金额走势图',
                textStyle: {
                    fontSize: 14,
                    fontWeight: 400
                },
                left: 24,
                top: 24,
            },
            //图形的位置
            grid: {
                top: 100
            },
            xAxis: {
                type: 'category',
                name: '时间',
                boundaryGap: false, //从点计算
                data: dayDate
            },
            yAxis: {
                name: '销售额(k)'
            },
            series: [
                {
                    type: 'line',
                    data: dayPrice,
                    //自定义线条颜色
                    lineStyle: {
                        normal: {
                            color: '#2194ff'
                        }
                    },
                    //设置折线向下颜色渐变
                    areaStyle: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [{//渐变颜色
                                offset: 0,
                                color: 'rgba(152,199,244,1)'
                            },
                                {
                                    offset: 1,
                                    color: 'rgba(152,199,244,0.1)'
                                }],
                            global: false,
                        }
                    }
                }
            ],
            tooltip: { // 鼠标悬浮提示框显示 X和Y 轴数据
                trigger: 'axis',
                backgroundColor: 'rgba(32, 33, 36,.7)',
                borderColor: 'rgba(32, 33, 36,0.20)',
                borderWidth: 1,
                textStyle: { // 文字提示样式
                    color: '#fff',
                    fontSize: '12'
                },
                axisPointer: { // 坐标轴虚线
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            }

        }
        // 使用刚指定的配置项和数据显示图表。
        generates.setOption(optiongenerates);
    }
})

$.get({
    url:'/homepage/getPriceWay',
    data:{},
    dataType:'json',
    async:false,
    success:res=>{
        var piceWay = []
        $.each(res.data,function (i){
            if (res.data[i].name == 1){
                res.data[i].name = '支付宝'
            }else if(res.data[i].name == 2){
                res.data[i].name = '微信'
            }else  if (res.data[i].name == 3){
                res.data[i].name = '银联'
            }else if(res.data[i].name == 4){
                res.data[i].name = '现金'
            }
        })
        piceWay = res.data
        var optionpayment = {
            title: {
                text: '支付方式占比',
                textStyle: {
                    fontSize: 14,
                    fontWeight: 400
                },
                left: 24,
                top: 24,
            },
            legend: {
                orient: 'vertical',
                left: 'right'
            },
            series: [
                {
                    type: 'pie',
                    data: piceWay,
                    radius: ['40%', '60%'],
                }
            ],
        }
        payment.setOption(optionpayment);
    }
})




